﻿using JsonRpcService.Contract;
using StreamJsonRpc;
using System.IO.Pipes;

namespace StreamSample.Client;

class Program
{
    static async Task Main(string[] args)
    {
        using var stream = new NamedPipeClientStream(".",
            "HelloJsonRpc",
            PipeDirection.InOut,
            PipeOptions.Asynchronous);

        Console.WriteLine("正在连接服务器...");
        await stream.ConnectAsync();
        Console.WriteLine("已建立连接！");

        var jsonRpc = JsonRpc.Attach(stream);

        Console.Write("请输入你的姓名：");
        var name = Console.ReadLine() ?? "json-rpc";
        var request = new HelloRequest { Name = name };
        Console.WriteLine("开始向服务端发送消息...");
        var response = await jsonRpc.InvokeAsync<HelloResponse>("SayHello", request);
        Console.WriteLine($"收到来自服务端的响应：{response.Message}");

        Console.ReadKey();
    }
}
